/**
 * Copyright © 2014 Winit Corp. All rights reserved.
 * This software is proprietary to and embodies the confidential
 * technology of Winit Corp.  Possession, use, or copying
 * of this software and media is authorized only pursuant to a
 * valid written license from Winit Corp or an authorized sublicensor.
 */
package com.winit.openapi.fna.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.common.spi.SPIException;
import com.winit.fna.spi.bill.SellerBillService;
import com.winit.fna.spi.bill.command.SellerBillCommand;
import com.winit.fna.spi.bill.vo.SellerBill;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;

/**
 * TODO weifeng.liu: Change to the actual description of this class
 * @version   Revision History
 * <pre>
 * Author     Version       Date        Changes
 * weifeng.liu    1.0           2015年6月19日     Created
 *
 * </pre>
 * @since 1.
 */
@Controller
@RequestMapping(value = "/fna/bill")
public class SellerBillController extends BaseController{

    @Autowired
    private SellerBillService sellerBillService;
    
    @RequestMapping(value = "/getSellerBill")
    public String getSellerBill(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        Object obj = requestMsg.getData();
        SellerBillCommand command = new SellerBillCommand();
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            try {
                command = JSONObject.toJavaObject(json, SellerBillCommand.class);
            } catch (SPIException e) {
                throw new SPIException("javaBean 转换错误");
            }
            SellerBill bill = sellerBillService.getSellerBill(command);
            if (null != bill) {
                responseMsg.setData(bill);
            }
        } else {
            throw new SPIException("json 格式错误");
        }
        return SUCCESS;
    }
}
